package com.qingke.serviceImp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qingke.dao.BlogDao;
import com.qingke.dao.CommentDao;
import com.qingke.dao.UserDao;
import com.qingke.pojo.Blog;
import com.qingke.pojo.Comment;
import com.qingke.pojo.User;
import com.qingke.service.UserService;

@Service("userService")
public class UserServiceImp implements UserService{
	@Autowired
	private BlogDao blogdao;
	@Autowired
	private UserDao userdao;
	@Autowired
	private CommentDao commentdao;
	
	public List<Blog> LookOverBlogOrderByTime(User user) {
		 return blogdao.OrderByCreatetime(user);
		
	}

	public List<Blog> LookOverBlogOrderByLikeAmmount() {
		return blogdao.OrderByLikeammount();
	}

	public List<Blog> LookOverBlogOrderByPageViews() {
		return blogdao.OrderByPageViews();
	}

	public boolean releaseBlog(User user, Blog blog) {
		
		blog.setUser(user);
	    return blogdao.insert(blog);
		
	}

	public boolean updateBlog(User user, Blog blog) {
		blog.setUser(user);
		return blogdao.update(blog);
	}

	public boolean deleteBlog(User user, Blog blog) {
		blog.setUser(user);
		return blogdao.delete(blog);
	}

	public List<Blog> GroupByTitle(String title) {
		 return blogdao.selectByTitle(title);
		
	}

	public List<Blog> GroupByDescription(String description) {
		return blogdao.selectByDescription(description);
	}

	public boolean Login(User user) {
		String username = user.getUsername();
		User u = (User) userdao.selectByUsername(username);
		if(user.getPassword().equals(u.getPassword())){
			return true;
		}else{
			return false;
		}
	}

	public boolean signUp(User user) {
		return userdao.insert(user);
	}

	public boolean Logout(User user) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean updateUser(User user) {
		return userdao.update(user);
	}

	public boolean deleteUser(User user) {
		return userdao.delete(user);
	}

	public User selectById(int userid) {
		return (User) userdao.selectById(userid);
	}

	public boolean releaseComment(User user,Comment comment,Blog blog) {
		comment.setBlog(blog);
		comment.setUser(user);
		return commentdao.insert(comment);
	}

	public List<Comment> LookOverCommentByBlog(User user, Blog blog) {
		 return commentdao.selectByBlog(blog);
		
	}

	public List<Comment> LookOverComment(User user) {
		return commentdao.selectByUser(user);
	}

	public boolean deleteComment(Comment comment) {
		return commentdao.delete(comment);
	}

}
